package com.example.UI.list;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


import com.example.UI.MainActivity;
import com.example.UI.entity.User;
import com.example.ui.R;

import java.util.List;

public class StudentArrayAdapter extends ArrayAdapter<User> {
    public StudentArrayAdapter(MainActivity context, List<User> users) {
        super(context, 0, users);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // Get the data item for this position
        User user = getItem(position);
        // Check if an existing view is being reused, otherwise inflate the view
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_user, parent, false);
        }
        // Lookup view for data population
        TextView tvClassName = (TextView) convertView.findViewById(R.id.tvClassName);
        TextView tvStudentId = (TextView) convertView.findViewById(R.id.tvStudentId);
        TextView tvName = (TextView) convertView.findViewById(R.id.tvName);

        // Populate the data into the template view using the data object
        tvClassName.setText("班级：" + user.getClass_name()); // 假设getClass_name()返回班级名称
        tvStudentId.setText("学号：" + user.getStudent_id()); // 假设getStudent_id()返回学号
        tvName.setText("班级：" + user.getName()); // 假设getName()返回姓名

        // Return the converted view to be inserted into the list
        return convertView;
    }
}
